package com.hjl.spring6.autowired.controller;

import com.hjl.spring6.autowired.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * @author ServivE
 * @version 0.1
 * @className UserController
 * @description
 * @date 2024/8/6 19:26
 * @since jdk11
 */
@Controller
public class UserController {

    //第一张方式注入service  属性注入
    /*@Autowired //根据类型找到对应对象，完成注入
    private UserService userService;*/

    //第二种方式set方法注入
  /*  private UserService userService;
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }*/
    //第三种方式 构造方法注入
 /*   private UserService userService;
    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }*/
    //第四种方式 形参上注入
   /* private UserService userService;

    public UserController(@Autowired UserService userService) {
        this.userService = userService;
    }*/
    //第五种方式，只有一个有参数构造函数，无注解
    private UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }
    public void add() {
        System.out.println("controller....");
        userService.addUserService();
    }

}
